import React from 'react'
import { Button, message, Form, Input ,Select} from 'antd';
export default function AddAccount(){
	const { Option } = Select;
    const onFinish = (values) => {
	  console.log('Success:', values);
	  fetch("http://jacklv.cn/users/addOrEditAccount", {
	    method: "post",
	    body: JSON.stringify(values),
	    headers: {
	      "Content-Type": "application/json",
		  token:localStorage.token
	    }
	  })
	    .then(response => {
	      return response.json();
	    })
	    .then(res => {
	      console.log('res', res)
	      if(res.code == 1){
	        message.success("添加成功");
	      }else{
	        message.error("用户已存在")
	      }
	    })
	    .catch(err=>{
	      console.log("err",err);
	    })
	};
	
	const onFinishFailed = (errorInfo) => {
	  console.log('Failed:', errorInfo);
	};
	return (<div><Form
	  name="basic"
	  labelCol={{ span: 8 }}
	  wrapperCol={{ span: 16 }}
	  style={{ Width: 400 }}
	  initialValues={{ select: '普通管理员' }}
	  onFinish={onFinish}
	  onFinishFailed={onFinishFailed}
	  autoComplete="off"
	>
	  <Form.Item
	    label={<div style={{color:'white'}}>用户名</div>}
	    name="account"
	    rules={[{ required: true, message: '请输入账户名!' }]}
	  >
	    <Input placeholder="请输入账户名"/>
	  </Form.Item>
	
	  <Form.Item
	    label={<div style={{color:'white'}}>密码</div>}
	    name="password"
	    rules={[{ required: true, message: '请输入密码!' }]}
	  >
	    <Input.Password />
	  </Form.Item>
	    <Form.Item
	      name="select"
	      label="Select"
	      hasFeedback
	      rules={[
	        {
	          required: true,
	          message: '请选择!',
	        },
	      ]}
	    >
	      <Select placeholder="请选择!">
	        <Option value="超级管理员">超级管理员</Option>
	        <Option value="普通管理员">普通管理员</Option>
	      </Select>
	    </Form.Item>
	  <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
	    <Button type="primary" htmlType="submit">
	      添加
	    </Button>
	  </Form.Item>
	</Form></div>)
}

